package edu.uoc.tds.pec4.vista;

import edu.uoc.tds.pec4.excepciones.FechasIncongruentesException;
import edu.uoc.tds.pec4.gestor.GestorEvento;
import edu.uoc.tds.pec4.gestor.impl.GestorEventoImpl;
import edu.uoc.tds.pec4.model.SS1_CentroDocente;
import edu.uoc.tds.pec4.model.SS2_Evento;
import edu.uoc.tds.pec4.util.ComponentsUtils;
import edu.uoc.tds.pec4.util.ExceptionUtils;
import edu.uoc.tds.pec4.util.KeyValue;
import edu.uoc.tds.pec4.util.LanguageUtils;
import java.awt.BorderLayout;
import java.rmi.RemoteException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.table.DefaultTableModel;

/**
 * Tecnicas de Desarrollo de Software - (UOC)
 * Clase para representar modificar un evento en el sistema.
 * @author Grupo Magicsoftware - Yolanda Jiménez Anaya
 * @version 1.0
 */

public class SS2_PantallaModificaEvento extends javax.swing.JPanel {

    public GestorEvento objetoRemoto;
    private SS2_PantallaAltaEvento sS2_PanelAltaEvento;
    /** Creates new form Prueba */
    public SS2_PantallaModificaEvento(GestorEvento objetoRemoto) {
        this.objetoRemoto = objetoRemoto;
        initComponents();
       //Rellenamos el combo de centros
        jComboBoxCentro.setSelectedItem(jComboBoxCentro);
        setListCentrosToCombo(jComboBoxCentro);
        LimpiarCampos();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanelInicio = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jSeparator1 = new javax.swing.JSeparator();
        ButtonBuscar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jComboBoxCentro = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        FechaHasta = new javax.swing.JFormattedTextField();
        jLabel2 = new javax.swing.JLabel();
        FechaDesde = new javax.swing.JFormattedTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabelNombre1 = new javax.swing.JLabel();
        jTextFieldNombre1 = new javax.swing.JTextField();
        jLabelFeIni1 = new javax.swing.JLabel();
        jTextFeIni1 = new javax.swing.JTextField();
        jLabelFeFin1 = new javax.swing.JLabel();
        jTextFeFin1 = new javax.swing.JTextField();
        jLabelFeCel1 = new javax.swing.JLabel();
        jTextFeCel1 = new javax.swing.JTextField();
        jLabelUmbral2 = new javax.swing.JLabel();
        jTextFieldUmbral1 = new javax.swing.JTextField();
        jLabelUmbral3 = new javax.swing.JLabel();
        jTextFieldCap1 = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jTextFieldPrecio1 = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jTextFieldCre1 = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jTextFieldDura1 = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jTextFieldPlaz1 = new javax.swing.JTextField();
        jLabelTipo1 = new javax.swing.JLabel();
        jLabelEvRe1 = new javax.swing.JLabel();
        jLabelRolRe1 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jScrollPane9 = new javax.swing.JScrollPane();
        jTextDes = new javax.swing.JTextArea();
        jScrollPane6 = new javax.swing.JScrollPane();
        jListRequi = new javax.swing.JList();
        jScrollPane10 = new javax.swing.JScrollPane();
        jListRol = new javax.swing.JList();
        ButtonModificar = new javax.swing.JButton();
        jComboBoxTipo = new javax.swing.JComboBox();
        jScrollPane7 = new javax.swing.JScrollPane();
        jList3 = new javax.swing.JList();

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Fecha", "Evento", "Centro", "Duración"
            }
        ));
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        ButtonBuscar.setText("Buscar");
        ButtonBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonBuscarActionPerformed(evt);
            }
        });

        jLabel1.setText("Centro");

        jLabel3.setText("Fecha Hasta:");

        FechaHasta.setText("dd/mm/yyyy");

        jLabel2.setText("Fecha Desde:");

        FechaDesde.setText("dd/mm/yyyy");

        jLabel4.setText("Buscar Evento.");

        jLabelNombre1.setText("Nombre:");

        jLabelFeIni1.setText("Fecha Inicio");

        jTextFeIni1.setText("dd/mm/yyyy");

        jLabelFeFin1.setText("Fecha Fin:");

        jTextFeFin1.setText("dd/mm/yyyy");

        jLabelFeCel1.setText("Fecha Celebracion:");

        jTextFeCel1.setText("dd/mm/yyyy");

        jLabelUmbral2.setText("Umbral %");

        jTextFieldUmbral1.setText("%");

        jLabelUmbral3.setText("Capacidad:");

        jLabel10.setText("Precio:");

        jLabel11.setText("Creditos:");

        jTextFieldCre1.setText("0");

        jLabel12.setText("Duracion (en min):");

        jTextFieldDura1.setText("0");

        jLabel13.setText("Plazas:");

        jTextFieldPlaz1.setText("0");

        jLabelTipo1.setText("Tipo:");

        jLabelEvRe1.setText("Eventos Requisito");

        jLabelRolRe1.setText("Rol Requisito");

        jLabel14.setText("Descripcion");

        jTextDes.setColumns(20);
        jTextDes.setRows(5);
        jScrollPane9.setViewportView(jTextDes);

        jListRequi.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane6.setViewportView(jListRequi);

        jListRol.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane10.setViewportView(jListRol);

        ButtonModificar.setText("Modificar");
        ButtonModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonModificarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelInicioLayout = new javax.swing.GroupLayout(jPanelInicio);
        jPanelInicio.setLayout(jPanelInicioLayout);
        jPanelInicioLayout.setHorizontalGroup(
            jPanelInicioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelInicioLayout.createSequentialGroup()
                .addGroup(jPanelInicioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelInicioLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanelInicioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanelInicioLayout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(18, 18, 18)
                                .addComponent(jComboBoxCentro, 0, 419, Short.MAX_VALUE)
                                .addGap(105, 105, 105)
                                .addComponent(ButtonBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 628, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanelInicioLayout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel2)
                                .addGap(18, 18, 18)
                                .addComponent(FechaDesde, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel3)
                                .addGap(18, 18, 18)
                                .addComponent(FechaHasta, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 677, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanelInicioLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanelInicioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelFeFin1)
                            .addComponent(jLabelFeIni1)
                            .addGroup(jPanelInicioLayout.createSequentialGroup()
                                .addGroup(jPanelInicioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanelInicioLayout.createSequentialGroup()
                                        .addComponent(jLabelNombre1)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTextFieldNombre1, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanelInicioLayout.createSequentialGroup()
                                        .addGroup(jPanelInicioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabelUmbral2)
                                            .addComponent(jLabelUmbral3)
                                            .addComponent(jLabel10)
                                            .addComponent(jLabel13)
                                            .addComponent(jLabel12)
                                            .addComponent(jLabel11))
                                        .addGap(39, 39, 39)
                                        .addGroup(jPanelInicioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addComponent(jTextFieldPlaz1, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jTextFieldDura1, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jTextFieldCre1)
                                            .addComponent(jTextFieldPrecio1, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jTextFieldCap1, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jTextFieldUmbral1, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jTextFeCel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jTextFeFin1, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jTextFeIni1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addComponent(jLabelFeCel1))
                                .addGap(37, 37, 37)
                                .addGroup(jPanelInicioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabelRolRe1)
                                    .addComponent(jLabel14)
                                    .addComponent(jLabelEvRe1)
                                    .addComponent(jLabelTipo1))))
                        .addGroup(jPanelInicioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanelInicioLayout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(jPanelInicioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jScrollPane9)
                                    .addComponent(jScrollPane10, javax.swing.GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
                                    .addComponent(jScrollPane6)
                                    .addComponent(jComboBoxTipo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                            .addGroup(jPanelInicioLayout.createSequentialGroup()
                                .addGap(181, 181, 181)
                                .addComponent(ButtonModificar, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(2439, Short.MAX_VALUE))
        );
        jPanelInicioLayout.setVerticalGroup(
            jPanelInicioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelInicioLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanelInicioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel2)
                    .addComponent(FechaDesde, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(FechaHasta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelInicioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jComboBoxCentro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ButtonBuscar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelInicioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelNombre1)
                    .addComponent(jTextFieldNombre1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelTipo1)
                    .addComponent(jComboBoxTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelInicioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelFeIni1)
                    .addComponent(jTextFeIni1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelInicioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelInicioLayout.createSequentialGroup()
                        .addGroup(jPanelInicioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelFeFin1)
                            .addComponent(jLabelEvRe1)
                            .addComponent(jTextFeFin1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelInicioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanelInicioLayout.createSequentialGroup()
                                .addGap(6, 6, 6)
                                .addGroup(jPanelInicioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabelFeCel1)
                                    .addComponent(jTextFeCel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanelInicioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabelUmbral2)
                                    .addComponent(jTextFieldUmbral1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanelInicioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabelUmbral3)
                                    .addComponent(jTextFieldCap1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanelInicioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel10)
                                    .addGroup(jPanelInicioLayout.createSequentialGroup()
                                        .addComponent(jTextFieldPrecio1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(9, 9, 9)
                                        .addGroup(jPanelInicioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jTextFieldCre1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel11))))
                                .addGap(8, 8, 8)
                                .addGroup(jPanelInicioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jTextFieldDura1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel12)))
                            .addGroup(jPanelInicioLayout.createSequentialGroup()
                                .addGap(72, 72, 72)
                                .addComponent(jLabel14)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelInicioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldPlaz1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel13)))
                    .addGroup(jPanelInicioLayout.createSequentialGroup()
                        .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelInicioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelRolRe1)
                            .addGroup(jPanelInicioLayout.createSequentialGroup()
                                .addComponent(jScrollPane10, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jScrollPane9, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(38, 38, 38)
                        .addComponent(ButtonModificar)))
                .addGap(214, 214, 214))
        );

        jList3.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane7.setViewportView(jList3);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanelInicio, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(290, 290, 290)
                .addComponent(jScrollPane7, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE)
                .addGap(936, 936, 936))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(241, 241, 241)
                .addComponent(jScrollPane7, 0, 0, Short.MAX_VALUE)
                .addGap(424, 424, 424))
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanelInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(19, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void ButtonBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonBuscarActionPerformed
      String validarCamposObligatoriosMessage = validarCamposObligatorios(jComboBoxCentro.getItemAt(jComboBoxCentro.getSelectedIndex()).toString(),
                   FechaDesde.getText(),
                   FechaHasta.getText());
            if ("".equals(validarCamposObligatoriosMessage)) {
                LimpiarCampos();
                buscarEventos();
            }else {
            ExceptionUtils.visualizarError(LanguageUtils.getMessage("CancelarEventos.CamposObligatorios") + validarCamposObligatoriosMessage);
        }
}//GEN-LAST:event_ButtonBuscarActionPerformed
 private void buscarEventos() {
        try {
            System.out.print("Dentro de BuscarEventos 1: " + jComboBoxCentro.getItemAt(jComboBoxCentro.getSelectedIndex()).toString());
            String validarCondicionesMessage = validarEventos();
            if ("".equals(validarCondicionesMessage)) {
                 //Rellenamos el combo de tipos de evento
                jComboBoxTipo.setSelectedItem(jComboBoxTipo);
                setListTiposToCombo(jComboBoxTipo);

                String v_CodigoCentro = "0";

                KeyValue kv1 = (KeyValue) jComboBoxCentro.getItemAt(jComboBoxCentro.getSelectedIndex());
                v_CodigoCentro = (String) kv1.getKey();

                try{
                List<SS2_Evento> list = objetoRemoto.getListaEvento(v_CodigoCentro,
                   FechaDesde.getText(),
                   FechaHasta.getText());

                borrarElementosTabla();
                //Comprobamos que la consulta nos ha devuelto datos
                if (list.size() > 0) {
                    DefaultTableModel tm = (DefaultTableModel) jTable1.getModel();
                    for (int i = 0; i < list.size(); i++) {
                        SS2_Evento eventos = list.get(i);
                        Object[] rowData = new Object[]{eventos.getfechaCelebracion(), eventos.getidEvento(), eventos.getNombre(), eventos.getCodCentro(), eventos.getduracion(), eventos.getCheckin() };
                        tm.insertRow(i, rowData);
                    }
                } else {
                    ExceptionUtils.visualizarInformacion(LanguageUtils.getMessage("CancelarEvento.NoDatos"));
                }
}
                catch (IllegalArgumentException ex) {
                   ExceptionUtils.visualizarInformacion(LanguageUtils.getMessage("SS3.error.formato.incorrecto"));
                   Logger.getLogger(SS2_PantallaCancelarEvento.class.getName()).log(Level.SEVERE, null, ex);
                } catch (FechasIncongruentesException ex) {
                   ExceptionUtils.visualizarInformacion(LanguageUtils.getMessage("SS3.error.formato.fecha.incongruentes"));
                   Logger.getLogger(SS2_PantallaCancelarEvento.class.getName()).log(Level.SEVERE, null, ex);
                } catch (ParseException ex) {
                   ExceptionUtils.visualizarInformacion(LanguageUtils.getMessage("SS3.error.formato.fecha.incorrecta"));
                   Logger.getLogger(SS2_PantallaCancelarEvento.class.getName()).log(Level.SEVERE, null, ex);
                } catch (RemoteException ex) {
                   ExceptionUtils.visualizarError(LanguageUtils.getMessage("ERR_Remote"));
                   Logger.getLogger(SS2_PantallaCancelarEvento.class.getName()).log(Level.SEVERE, null, ex);
                }
            } else {
                ExceptionUtils.visualizarError(validarCondicionesMessage);
            }
        } catch (RemoteException ex) {
            ExceptionUtils.visualizarError(ExceptionUtils.ERR_Remote);
        } catch (Exception ex) {
            ExceptionUtils.visualizarError(LanguageUtils.getMessage("CancelarEvento.ERR_BuscarRegistros"));
        }
    }

      /*
     * Metodo que comprueba que se han introducido los campos obligatorios y el formato
     */
    private String validarEventos() throws RemoteException, Exception {
        //Validar que tiene un evento seleccionado
        KeyValue kv1 = (KeyValue) jComboBoxCentro.getItemAt(jComboBoxCentro.getSelectedIndex());
        System.out.print(" ---kv1 : " +kv1);
        if (kv1 == null) {
            return LanguageUtils.getMessage("CancelarEvento.Errores.NoHayCentros");
        }
        return "";
    }
     /*
    * Metodo que comprueba que se han introducido los campos obligatorios
    */
    private String validarCamposObligatorios(String centro,
            String FechaIni,
            String FechaFin) {

        System.out.println("Vamos a comprobar campos obligatorios");
        StringBuilder campos = new StringBuilder();
        try {
            if (centro == null || "".equals(centro)) {
                campos.append(LanguageUtils.getMessage("AltaEventos.CampoObligatorio.Centro"));
                borrarElementosTabla();
            }
            if (FechaIni == null || "".equals(FechaIni)) {
                campos.append(LanguageUtils.getMessage("AltaEventos.CampoObligatorio.FechaInicio"));
                borrarElementosTabla();
            }
            if (FechaFin == null || "".equals(FechaFin)) {
                campos.append(LanguageUtils.getMessage("AltaEventos.CampoObligatorio.FechaFin"));
                borrarElementosTabla();
            }

        } catch (Exception e) {
            ExceptionUtils.visualizarError(LanguageUtils.getMessage("AltaEventos.ERR_Validar"));
            borrarElementosTabla();
        }

        return campos.toString();
    }

    private void borrarElementosTabla() {
        DefaultTableModel tm = (DefaultTableModel) jTable1.getModel();
        if (tm != null && tm.getDataVector() != null) {
            tm.getDataVector().removeAllElements();
            jTable1.updateUI();
        }
    }
    
    private void ButtonModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonModificarActionPerformed
        try {
             boolean result = false;
            SimpleDateFormat formatoDelTexto = new SimpleDateFormat("dd/MM/yyyy");
            String v_CodigoCentro = "0";
            KeyValue kv1 = (KeyValue) jComboBoxCentro.getItemAt(jComboBoxCentro.getSelectedIndex());
            v_CodigoCentro = (String) kv1.getKey();
            String v_TipoEvento = "0";
            KeyValue kv2 = (KeyValue) jComboBoxTipo.getItemAt(jComboBoxTipo.getSelectedIndex());
            v_TipoEvento = (String) kv2.getKey();
            Date FechaIni = formatoDelTexto.parse(jTextFeIni1.getText());
            Date FechaFin = formatoDelTexto.parse(jTextFeFin1.getText());
            Date FechaCelebracion = formatoDelTexto.parse(jTextFeCel1.getText());
            String Capacidad = jTextFieldCap1.getText();

            SS2_Evento EventoModifica = new SS2_Evento(Integer.parseInt(v_CodigoCentro),
                    jTextFieldNombre1.getText(),
                    jTextDes.getText(),
                    new Date(), 
                    FechaCelebracion,
                    "1",
                    new Date(), 
                    "Create",
                    Integer.parseInt(v_TipoEvento), 
                    Integer.parseInt(Capacidad), 
                    FechaIni,
                    FechaFin,
                    jTextFieldDura1.getText(),
                    Integer.parseInt(jTextFieldPrecio1.getText()),
                    Integer.parseInt(jTextFieldPlaz1.getText()),
                    Integer.parseInt(jTextFieldUmbral1.getText()),
                    Integer.parseInt(jTextFieldCre1.getText()));
            try {
                String v_Evento = jTable1.getValueAt(jTable1.getSelectedRow(), 1).toString();

                result = objetoRemoto.modificaEvento(EventoModifica,v_Evento);
                if(!result){
                      ExceptionUtils.visualizarInformacion(LanguageUtils.getMessage("ModificaEventos.Correcto"));
                 }else {
                    ExceptionUtils.visualizarError(LanguageUtils.getMessage("ModificaEventos.Error"));
                }
            } catch (RemoteException ex) {
                Logger.getLogger(SS2_PantallaModificaEvento.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (ParseException ex) {
            Logger.getLogger(SS2_PantallaModificaEvento.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_ButtonModificarActionPerformed

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
        System.out.println("Al pulsado en: ");
         String v_Evento = jTable1.getValueAt(jTable1.getSelectedRow(), 1).toString();
         String v_Centro = jTable1.getValueAt(jTable1.getSelectedRow(), 2).toString();

         System.out.println("Al pulsado en: v_Evento: " + v_Evento + " v_Centro: " + v_Centro +"\n" );
        try {
            SS2_Evento eventos = objetoRemoto.leeEvento(Integer.parseInt(v_Evento.toString()));
            DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
            System.out.print("Obtenemos Nombre: " + eventos.getNombre().toString());
            jTextFieldNombre1.setText(eventos.getNombre()) ;
            jTextFeIni1.setText(sdf.format(eventos.getfechaInicioInscripcion()));
            jTextFeFin1.setText(sdf.format(eventos.getfechaFinIncripcion()));
            jTextFeCel1.setText(sdf.format(eventos.getfechaCelebracion()));
            jTextFieldUmbral1.setText(Integer.toString(eventos.getUmbral()));
            jTextFieldCap1.setText(Integer.toString(eventos.getcapacidad()));
            jTextFieldPrecio1.setText(Integer.toString(eventos.getprecio()));
            jTextFieldCre1.setText(Integer.toString(eventos.getCreditos()));
            jTextFieldDura1.setText(eventos.getduracion());
            jTextFieldPlaz1.setText(Integer.toString(eventos.getPlazas()));
            jTextDes.setText(eventos.getdescripcion());

           
            //jComboBoxTipo.selectWithKeyChar((char) eventos.gettipoEvento());
                 //Rellenamos el combo de tipos de evento
                /*jComboBoxTipo.setSelectedItem(jComboBoxTipo);
                setListTiposToCombo(jComboBoxTipo);*/

                String v_TipoEvento = "0";

                KeyValue kv1 = (KeyValue) jComboBoxTipo.getItemAt(jComboBoxTipo.getSelectedIndex());
                v_TipoEvento = (String) kv1.getKey();

                jComboBoxTipo.setSelectedItem(eventos.gettipoEvento());


             
        } catch (RemoteException ex) {
            Logger.getLogger(SS2_PantallaModificaEvento.class.getName()).log(Level.SEVERE, null, ex);
        }





    }//GEN-LAST:event_jTable1MouseClicked


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton ButtonBuscar;
    private javax.swing.JButton ButtonModificar;
    private javax.swing.JFormattedTextField FechaDesde;
    private javax.swing.JFormattedTextField FechaHasta;
    private javax.swing.JComboBox jComboBoxCentro;
    private javax.swing.JComboBox jComboBoxTipo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabelEvRe1;
    private javax.swing.JLabel jLabelFeCel1;
    private javax.swing.JLabel jLabelFeFin1;
    private javax.swing.JLabel jLabelFeIni1;
    private javax.swing.JLabel jLabelNombre1;
    private javax.swing.JLabel jLabelRolRe1;
    private javax.swing.JLabel jLabelTipo1;
    private javax.swing.JLabel jLabelUmbral2;
    private javax.swing.JLabel jLabelUmbral3;
    private javax.swing.JList jList3;
    private javax.swing.JList jListRequi;
    private javax.swing.JList jListRol;
    public static javax.swing.JPanel jPanelInicio;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane10;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JScrollPane jScrollPane9;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextArea jTextDes;
    private javax.swing.JTextField jTextFeCel1;
    private javax.swing.JTextField jTextFeFin1;
    private javax.swing.JTextField jTextFeIni1;
    private javax.swing.JTextField jTextFieldCap1;
    private javax.swing.JTextField jTextFieldCre1;
    private javax.swing.JTextField jTextFieldDura1;
    private javax.swing.JTextField jTextFieldNombre1;
    private javax.swing.JTextField jTextFieldPlaz1;
    private javax.swing.JTextField jTextFieldPrecio1;
    private javax.swing.JTextField jTextFieldUmbral1;
    // End of variables declaration//GEN-END:variables
    private JPanel panelCentral;

        /*
     * Metodo para rellenar el despegable de centros
     */
    private void setListCentrosToCombo(JComboBox combo) {
        try {
            List<SS1_CentroDocente> list = objetoRemoto.dameListaCentros();
            if (list != null && list.size() > 0) {
                for (SS1_CentroDocente CentroDocente : list) {
                    combo.addItem(new KeyValue(Integer.toString(CentroDocente.getId()), CentroDocente.getNombre()));
                }
            }
        } catch (RemoteException ex) {
            ExceptionUtils.visualizarError(ExceptionUtils.ERR_Remote);
        } catch (Exception ex) {
            ExceptionUtils.visualizarError(LanguageUtils.getMessage("AltaEvento.ERR_Centros"));
        }
    }

      /*
     * Metodo para rellenar el despegable de Tipos de Evento
     */
    private void setListTiposToCombo(JComboBox combo) {
        try {
            List<SS1_CentroDocente> list = objetoRemoto.dameListaTipo();
            if (list != null && list.size() > 0) {
                for (SS1_CentroDocente CentroDocente : list) {
                    combo.addItem(new KeyValue(Integer.toString(CentroDocente.getId()), CentroDocente.getNombre()));
                }
            }
        } catch (RemoteException ex) {
            ExceptionUtils.visualizarError(ExceptionUtils.ERR_Remote);
        } catch (Exception ex) {
            ExceptionUtils.visualizarError(LanguageUtils.getMessage("AltaEvento.ERR_TipoEvento"));
        }
    }

    private void LimpiarCampos(){
            jTextFieldNombre1.setText("            ") ;
            jTextFeIni1.setText("                        ");
            jTextFeFin1.setText("                        ");
            jTextFeCel1.setText("                        ");
            jTextFieldUmbral1.setText("                        ");
            jTextFieldCap1.setText("                        ");
            jTextFieldPrecio1.setText("                        ");
            jTextFieldCre1.setText("                        ");
            jTextFieldDura1.setText("                        ");
            jTextFieldPlaz1.setText("                        ");
            jTextDes.setText("                        ");
    }

}

